package com.wdd.recoveryvehicle.mapper;

import com.wdd.recoveryvehicle.sysToken.bean.SysToken;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

/**
 * token
 *
 * @author globalMr
 */
@Mapper
@Repository
public interface TokenMapper {
    /**
     * 查询 token对象 --- user_id
     *
     * @param user_id
     * @return
     */
    @Select(" select user_id, expire_time, token, update_time from sys_token where user_id = #{user_id} ")
    SysToken selectSysTokenByUserId(@Param("user_id") String user_id);

    /**
     * 查询 token对象 --- token
     *
     * @param token
     * @return
     */
    @Select(" select user_id, expire_time, token, update_time from sys_token where token = #{token} ")
    SysToken selectSysTokenByToken(@Param("token") String token);

    /**
     * 插入 token对象
     *
     * @param sysToken
     * @return
     */
    @Insert(" insert into sys_token " +
            " set user_id = #{sysToken.user_id}, expire_time = #{sysToken.expire_time}, token = #{sysToken.token}, update_time = #{sysToken.update_time} ")
    boolean insertSysToken(@Param("sysToken") SysToken sysToken);

    /**
     * 更新 token对象
     *
     * @param sysToken
     * @return
     */
    @Update(" update sys_token " +
            " set expire_time = #{sysToken.expire_time}, update_time = #{sysToken.update_time}, token = #{sysToken.token} " +
            " where user_id = #{sysToken.user_id} ")
    boolean updateSysTokenByUserId(@Param("sysToken") SysToken sysToken);

    /**
     * 删除 token对象
     *
     * @param user_id
     * @return
     */
    @Delete(" delete from sys_token where user_id = #{user_id} ")
    boolean deleteSysTokenByUserId(@Param("user_id") String user_id);


}
